package com.letoken.platform.job.jobhandler.monitor;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.letoken.platform.job.redis.EmailSendRedis;
import com.letoken.platform.pub.constant.RedisKeyConstant;
import com.letoken.platform.pub.enums.ShopStateEnum;
import com.letoken.platform.pub.util.DateUtil;
import com.letoken.platform.pub.util.EmailUtil;
import com.letoken.platform.pub.util.LocalDateTool;
import com.letoken.platform.pub.util.MD5Util;
import com.letoken.platform.repo.admin.po.Withdraw;
import com.letoken.platform.repo.mall.dao.AppMallDayStatisticsMapper;
import com.letoken.platform.repo.mall.dao.AppMallInfoMapper;
import com.letoken.platform.repo.mall.dao.AppMallOrderInfoMapper;
import com.letoken.platform.repo.mall.dao.AppMallStatisticsMapper;
import com.letoken.platform.repo.mall.po.AppMallDayStatistics;
import com.letoken.platform.repo.mall.po.AppMallInfo;
import com.letoken.platform.repo.mall.po.AppMallOrderInfo;
import com.letoken.platform.repo.mall.req.InitOldData;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Component
@Log4j2
public class MallOnceJob {

    @Autowired
    AppMallInfoMapper appMallInfoMapper;
    @Autowired
    AppMallDayStatisticsMapper appMallDayStatisticsMapper;
    @Autowired
    AppMallStatisticsMapper appMallStatisticsMapper;
    @Autowired
    AppMallOrderInfoMapper appMallOrderInfoMapper;

    @XxlJob("initHistoryData")
    public void initHistoryData() {
        // 今天0点 只计算到昨天
//        LocalDateTime endTime = LocalDateTool.plusDay(LocalDateTime.now(),0);
//
//        List<InitOldData> list = appMallOrderInfoMapper.groupByDate(endTime);
//
//        if (CollectionUtils.isNotEmpty(list)){
//            list.forEach(x->{
//                AppMallDayStatistics dayStatistics = new AppMallDayStatistics();
//                BeanUtils.copyProperties(x,dayStatistics);
//                Integer id = null;
//                if (null != (id = appMallDayStatisticsMapper.recordIsExits(x.getMallId(),x.getDate()))){
//                    dayStatistics.setId(id);
//                    appMallDayStatisticsMapper.updateById(dayStatistics);
//                }else {
//                    appMallDayStatisticsMapper.insert(dayStatistics);
//                }
//            });
//        }

    }


}
